-
Notifications
You must be signed in to change notification settings - Fork 260
challenges #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
challenges #18
Conversation
n05tr0m0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Прокомментировал
| if is_male[name]: | ||
| print(f'{name} мужской род') | ||
| else: | ||
| print(f'{name} женский род') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно одной строкой в данном случае:
print(name, 'мужской пол') if is_male[name] else print(name, 'женский пол')|
|
||
| students_names = count_name(students) | ||
| for name, repeats in students_names.items(): | ||
| print(f'{name}: {repeats}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Решение без Counter для ознакомления:
count_students = {}
for student in students:
if student['first_name'] not in count_students.keys():
count_students[student['first_name']] = 1
else:
count_students[student['first_name']] += 1
print(count_students)
for name, count in count_students.items():
print(f"{name}: {count}")| names = count_name(students) | ||
| most_common_name = name_max_value(names) | ||
| print(f'Самое частое имя в классе: {most_common_name}') | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Решение без Counter, для ознакомления:
students_list = [student['first_name'] for student in students]
print("Самое частое имя среди учеников:", max(set(students_list), key=students_list.count))| for i, school_class in enumerate(school_students): | ||
| names = count_name(school_class) | ||
| most_common_name = name_max_value(names) | ||
| print(f'Самое частое имя в классе {i+1}: {most_common_name}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Переиспользование уже написанных функций хороший подход.
Публикую решение без использования Counter для ознакомления:
for num, students in enumerate(school_students, start=1):
students_list = [student['first_name'] for student in students]
print(f"Самое частое имя в классе {num}: {max(set(students_list), key=students_list.count)}")Почитай, попробуй разобраться как это работает, если не получится, напиши мне.
| for school_class in school: | ||
| gender = students_gender(school_class['students']) | ||
| class_name = school_class['class'] | ||
| print(f"Класс {class_name}: девочки {gender['Female']}, мальчики {gender['Male']}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ещё два способа решения для этой задачи для ознакомления:
for class_ in school:
count_boys = 0
count_girls = 0
for student in class_['students']:
if is_male[student['first_name']]:
count_boys += 1
else:
count_girls += 1
print(f"Класс {class_['class']}: девочки {count_girls}, мальчики {count_boys}")
print("альтернативный способ") # альтернативный способ
for class_ in school:
female = [name['first_name'] for name in class_['students'] if not is_male[name['first_name']]]
male = [name['first_name'] for name in class_['students'] if is_male[name['first_name']]]
print(f"Класс {class_['class']}: девочки {len(female)}, мальчики {len(male)}")There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Когда разберёшь, выполни 5-е задание
No description provided.